package com.million.eduservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.million.commonutils.R;
import com.million.eduservice.entity.vo.course.CourseInfoForm;
import com.million.eduservice.entity.vo.course.CourseInfoList;
import com.million.eduservice.entity.vo.course.CoursePublishVo;
import com.million.eduservice.entity.vo.course.CourseQuery;
import com.million.eduservice.service.EduCourseService;
import com.million.eduservice.service.EduVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author 十麓
 * @since 2022-03-24
 */
@Api(tags = "课程管理")
@RestController
@RequestMapping("/eduservice/course")
public class EduCourseController {

    @Autowired
    private EduCourseService eduCourseService;

    @ApiOperation(value = "分页条件查询")
    @PostMapping("/pageQueryCourse/{page}/{limit}")
    public R pageQueryCourse (@ApiParam(name = "page", value = "当前页码", required = true)
                        @PathVariable("page") Long page,
                        @ApiParam(name = "limit", value = "每页记录数", required = true)
                        @PathVariable("limit") Long limit,
                        @RequestBody CourseQuery courseQuery) {
        Page<CourseInfoList> courseListPage = new Page<>(page, limit);
        Page<CourseInfoList> courseList = eduCourseService.pageQueryCourse(courseListPage, courseQuery);
        return R.ok().data("courseList", courseList);
    }


    //添加课程信息
    @PostMapping("addCourseInfo")
    public R addCourseInfo (@RequestBody CourseInfoForm courseInfoForm) {
        String id = eduCourseService.addCourseInfo(courseInfoForm);
        return R.ok().data("courseId", id);
    }

    //通过课程id 得到课程信息
    @GetMapping("getCourseInfo/{id}")
    public R getCourseInfo (@PathVariable("id") String id) {
        CourseInfoForm courseInfoForm = eduCourseService.getCourseInfo(id);
        return R.ok().data("courseInfo", courseInfoForm);
    }

    //修改课程信息
    @PostMapping("updateCourseInfo")
    public R updateCourseInfo (@RequestBody CourseInfoForm courseInfoForm) {
        eduCourseService.updateCourseInfo(courseInfoForm);
        return R.ok();
    }

    //根据课程id查询课程确认信息
    @GetMapping("getPublishCourseInfo/{courseId}")
    public R getPublishCourseInfo (@PathVariable("courseId") String courseId) {
        CoursePublishVo coursePublishVo = eduCourseService.getPublishCourseInfo(courseId);
        return R.ok().data("coursePublishVo", coursePublishVo);
    }

    //课程提交，根据id将课程表中的status设置为已发布状态
    @PostMapping("publicCourse/{courseId}")
    public R publicCourse (@PathVariable("courseId") String courseId) {
        eduCourseService.publicCourse(courseId);
        return R.ok();
    }

    //删除课程信息
    @DeleteMapping("deleteCourseInfo/{courseId}")
    public R deleteCourseInfo(@PathVariable("courseId") String courseId){
        eduCourseService.deleteCourseInfo(courseId);
        return R.ok();
    }
}

